# -*- coding: utf-8 -*-
# @Time    : 2021/8/30 14:29
# @Author  : BrandonGT
import sys
from PyQt5.QtWidgets import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("测试")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):
        pass

    def mouseMoveEvent(self, evt):
        self.current_x, self.current_y = evt.globalX(), evt.globalY()
        # print(current_x, current_y)
        self.move((self.window_x - (self.temp_x-self.current_x)), self.window_y - (self.temp_y-self.current_y))

    def mousePressEvent(self, evt):
        self.setMouseTracking(True)
        self.temp_x, self.temp_y = evt.globalX(), evt.globalY()
        self.window_x, self.window_y = self.x(), self.y()

    def mouseReleaseEvent(self, QMouseEvent):
        self.setMouseTracking(False)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())